// DlgBackup.cpp : implementation file
//

#include "stdafx.h"
#include "BBViewer.h"
#include "DlgBackup.h"

#include "../_inc_util/UtilPath.h"
#include "../_inc_util/UtilTime.h"
#include "../_inc_util/UtilRender.h"
#include "../_inc_util/UtilString.h"
#include "StatusMgr.h"
#include "WndListTime.h"
#include "WndListEvent.h"
#include "../_inc/TimeList.h"

#include "../_inc_app/WndDisplay.h"
#include "DlgViewerBG.h"

// CDlgBackup dialog


IMPLEMENT_DYNAMIC(CDlgBackup, CDialog)

CDlgBackup::CDlgBackup(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgBackup::IDD, pParent)
	, m_nBackupType(0)
{
	m_pIntrBackup2		= NULL;

	m_dwBackupStartTime = time(0)-60;
	m_dwBackupEndTime = time(0);

	m_pWndListTime = NULL;
	m_nDlgStatus = 0;

	int i;
	for (i=0;i<MAX_CHANNEL;i++)
		m_bSelCam[i] = (i==0);

	for (i=0;i<MAX_CHANNEL;i++)
		m_pImageData[i] = NULL;

	m_pViewerSetup = NULL;
}

CDlgBackup::~CDlgBackup()
{
}

void CDlgBackup::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Radio(pDX, IDC_RADIO_BACKUP_TYPE1, m_nBackupType);
	DDX_Control(pDX, IDC_DATETIMEPICKER_START, m_dtpStart);
	DDX_Control(pDX, IDC_DATETIMEPICKER_END, m_dtpEnd);
	DDX_Control(pDX, IDC_STATIC_BACKUP_PATH, m_txtBackupPath);
	DDX_Control(pDX, IDC_PROGRESS_BACKUP, m_pgrBackup);
	DDX_Control(pDX, IDC_STATIC_BACKUP_START, m_txtBackupStart);
	DDX_Control(pDX, IDC_STATIC_BACKUP_END, m_txtBackupEnd);
	DDX_Control(pDX, IDOK, m_btnBackupStart);
	DDX_Control(pDX, IDCANCEL, m_btnClose);
	DDX_Control(pDX, IDC_BTN_STOP, m_btnStop);
}


BEGIN_MESSAGE_MAP(CDlgBackup, CDialog)
	ON_CONTROL_RANGE(BN_CLICKED, IDC_RADIO_BACKUP_TYPE1, IDC_RADIO_BACKUP_TYPE2, &CDlgBackup::OnBnClickedRadioBackupType)
	ON_BN_CLICKED(IDC_CHECK_BACKUP_CAM1, &CDlgBackup::OnBnClickedCheckBackupCam)
	ON_BN_CLICKED(IDC_CHECK_BACKUP_CAM2, &CDlgBackup::OnBnClickedCheckBackupCam)
	ON_BN_CLICKED(IDC_CHECK_BACKUP_CAM3, &CDlgBackup::OnBnClickedCheckBackupCam)
	ON_BN_CLICKED(IDC_CHECK_BACKUP_CAM4, &CDlgBackup::OnBnClickedCheckBackupCam)
	ON_BN_CLICKED(IDC_BTN_BACKUP_PATH, &CDlgBackup::OnBnClickedBtnBackupPath)
	ON_BN_CLICKED(IDOK, &CDlgBackup::OnBnClickedOk)
	ON_BN_CLICKED(IDCANCEL, &CDlgBackup::OnBnClickedCancel)
	ON_WM_SHOWWINDOW()
	ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER_START, &CDlgBackup::OnDtnDatetimechangeDatetimepickerStart)
	ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER_END, &CDlgBackup::OnDtnDatetimechangeDatetimepickerEnd)
	ON_BN_CLICKED(IDC_BTN_STOP, &CDlgBackup::OnBnClickedBtnStop)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON_OPEN_FOLDER, &CDlgBackup::OnBnClickedButtonOpenFolder)
END_MESSAGE_MAP()


// CDlgBackup message handlers
BOOL CDlgBackup::OnInitDialog()
{
	CDialog::OnInitDialog();

	LoadText();

	m_pgrBackup.SetRange(0, 100);
	m_pgrBackup.SetPos(0);

	int nCmdShow;
	if (m_nStartIndex<0)
		nCmdShow = SW_HIDE;
	else
		nCmdShow = SW_SHOW;

	GetDlgItem(IDC_RADIO_BACKUP_TYPE2)->ShowWindow(nCmdShow);
	m_txtBackupStart.ShowWindow(nCmdShow);
	m_txtBackupEnd.ShowWindow(nCmdShow);
	m_dtpStart.ShowWindow(nCmdShow);
	m_dtpEnd.ShowWindow(nCmdShow);

	switch (m_nRecMode)
	{
	case RECMODE_AV2:
	case RECMODE_SEPERATEINDEX:
	case RECMODE_SEPERATEFOLDER:
		m_dtpStart.EnableWindow(TRUE);
		m_dtpEnd.EnableWindow(TRUE);
		break;
	case RECMODE_AVI:
	case RECMODE_AVI_CURFOLDER:
	case RECMODE_AVI_SEPERATE:
		m_dtpStart.EnableWindow(FALSE);
		m_dtpEnd.EnableWindow(FALSE);
		break;
	}

	
	int i;
	CButton *pChk;
	VIEWER_SETTING stViewerSet = m_pViewerSetup->GetViewerSet();
	for (i=0;i<(int)stViewerSet.dwViewerMode;i++)
	{
		pChk = (CButton *)GetDlgItem(IDC_CHECK_BACKUP_CAM1+i);
		pChk->ShowWindow(SW_SHOW);
		pChk->SetCheck(m_bSelCam[i]);

	}

	for (;i<MAX_CHANNEL;i++)
	{
		GetDlgItem(IDC_CHECK_BACKUP_CAM1+i)->ShowWindow(SW_HIDE);

	}

	m_btnStop.EnableWindow(FALSE);
	m_bChangeTime = FALSE;

	m_pIntrBackup2 = IIntrBackup2::Create(stViewerSet.bCodec);
	m_pIntrBackup2->SetCallback(_CallbackBackup, this);
	m_pIntrBackup2->SetAVIFileNameFormat(m_stAVIFileNameFormat);
	m_pIntrBackup2->SetAudioFormat(theApp.dwAudioFormat, 
									theApp.dwAudioFrequency,
									theApp.dwAudioBitPerSample);

	return TRUE;
}

void CDlgBackup::OnBnClickedRadioBackupType(UINT nID)
{
	UpdateData(TRUE);
	UpdateControlData();
	UpdateData(FALSE);
	UpdateControl();
}

void CDlgBackup::UpdateControlData()
{
	if (m_nBackupType == Backup_Avi)
	{
		
	}
	else
	{
		
	}
}

void CDlgBackup::UpdateControl()
{	
	int nShow = (m_nBackupType == Backup_Avi)? SW_SHOW:SW_HIDE;

	m_txtBackupPath.SetWindowText(m_tzBackupPath);
	

	if (m_nStartIndex>=0)
	{
		m_txtBackupStart.ShowWindow(nShow);
		m_txtBackupEnd.ShowWindow(nShow);
		m_dtpStart.ShowWindow(nShow);
		m_dtpEnd.ShowWindow(nShow);
	}

	m_pgrBackup.ShowWindow(nShow);
	GetDlgItem(IDC_EDIT_PROGRESS_TIME)->ShowWindow(nShow);

	m_dtpStart.SetTime((time_t)(m_dwBackupStartTime+m_TimeZone.GetTimeZone()));
	m_dtpEnd.SetTime((time_t)(m_dwBackupEndTime+m_TimeZone.GetTimeZone()));

	m_pgrBackup.SetPos(0);
}

void CDlgBackup::SetProgressPos(int nPos, DWORD dwBackupTime)
{
	static DWORD dwOldBackupTime = 0;
	if (m_pgrBackup.GetPos() != nPos)
		m_pgrBackup.SetPos(nPos);

	if (dwOldBackupTime != dwBackupTime)
	{
		CUtilTime ut;
		TCHAR tzTime[64];
		dwOldBackupTime = dwBackupTime;

		ut.GetTimeString2(dwBackupTime, tzTime);
		SetDlgItemText(IDC_EDIT_PROGRESS_TIME, tzTime);
	}
}

void CDlgBackup::UpdateSetting()
{
	switch (m_nUpdateID)
	{
		case IDC_DATETIMEPICKER_START:
			{				
				SYSTEMTIME st;
				m_dtpStart.GetTime(&st);

				CTime startTime(st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

				m_dwBackupStartTime = startTime.GetTime()-m_TimeZone.GetTimeZone();

				break;
			}

		case IDC_DATETIMEPICKER_END:
			{
				SYSTEMTIME et;
				m_dtpEnd.GetTime(&et);

				CTime endTime(et.wYear, et.wMonth, et.wDay, et.wHour, et.wMinute, et.wSecond);

				m_dwBackupEndTime = endTime.GetTime()-m_TimeZone.GetTimeZone();
				break;
			}
	}
}

void CDlgBackup::OnBnClickedCheckBackupCam()
{
	int i;
	CButton *pChk;
	for (i=0;i<MAX_CHANNEL;i++)
	{
		pChk = (CButton *)GetDlgItem(IDC_CHECK_BACKUP_CAM1+i);
		m_bSelCam[i] = pChk->GetCheck();

	}
}

void CDlgBackup::OnBnClickedBtnBackupPath()
{
	CUtilPath util;
	TCHAR tzPath[MAX_PATH] = {0, };
	TCHAR tzTitle[MAX_PATH];
	wsprintf(tzTitle, _T("%s"), m_sarrText.GetAt(0));

	if (util.SelectFolder(m_hWnd, m_tzBackupPath, tzTitle, tzPath, TRUE))
	{
		wsprintf(m_tzBackupPath, _T("%s\\"), tzPath);
		VIEWER_SETTING stViewerSet;
		if (m_pViewerSetup)
		{
			stViewerSet = m_pViewerSetup->GetViewerSet();
			ZeroMemory(stViewerSet.tzSnapshotPath, sizeof(stViewerSet.tzSnapshotPath));
			wsprintf(stViewerSet.tzSnapshotPath, m_tzBackupPath);
			m_pViewerSetup->LoadViewerSet(&stViewerSet);
			UpdateControl();
		}
	}
}

TCHAR* CDlgBackup::GetBackupPath()
{
	return  m_tzBackupPath;
}

void CDlgBackup::SetBackupPath(TCHAR* tzPath)
{
	wsprintf(m_tzBackupPath, _T("%s"), tzPath);
}

void CDlgBackup::SetDbPath(DWORD dwRecType, TCHAR* tzPath)
{
	wsprintf(m_tzDbPath[dwRecType], _T("%s"), tzPath);
}

void CDlgBackup::SetBackupStartTime(DWORD dwStartTime)
{
	m_dwBackupStartTime	= dwStartTime;
	m_dwBackupEndTime	= m_dwBackupStartTime + 60;		
}

void CDlgBackup::SetBackupStartIndex(int nStartIndex, SEARCH_TYPE nSearchType)
{
	m_nStartIndex = nStartIndex;
	m_nSearchType = nSearchType;
	CTimeList *pIndex;

	if (nStartIndex<0)
	{
		m_dwBackupStartTime = time(0)-60;
		m_dwBackupEndTime = time(0);

		m_nDlgStatus = 0;
	}
	else
	{
		if (m_nSearchType == search_time)
		{
			pIndex = m_pWndListTime->GetRecIndex(nStartIndex);
			m_dwBackupStartTime = pIndex->GetStartTime();
			m_dwBackupEndTime = pIndex->GetEndTime();
		}
		else
		{
			pIndex = m_pWndListEvent->GetRecIndex(nStartIndex);
			m_dwBackupStartTime = pIndex->GetStartTime();
			m_dwBackupEndTime = pIndex->GetEndTime();
		
		}

		m_nDlgStatus = 1;
	}
}

void CDlgBackup::SetTimeListObject(CWndListTime *pWndListTime)
{
	m_pWndListTime = pWndListTime;
}

void CDlgBackup::SetEventListObject(CWndListEvent *pWndListEvent)
{
	m_pWndListEvent = pWndListEvent;
}

void CDlgBackup::OnBnClickedOk()
{
	BOOL bCheck = FALSE;
	int i;
	for (i=0;i<MAX_CHANNEL;i++)
	{
		bCheck = (bCheck || m_bSelCam[i]);
	}

	if (bCheck == FALSE)
	{
		AfxMessageBox(m_sarrMessage.GetAt(0));
		return;
	}

	if (m_nBackupType == Backup_Avi)
	{	
		if (m_dwBackupEndTime <= m_dwBackupStartTime)
		{
			CString strMessage;
			strMessage.Format(_T("%s\r\n%s"), m_sarrMessage.GetAt(1), m_sarrMessage.GetAt(2));
			AfxMessageBox(strMessage);
			return;		
		}

		//find index
		int nIndexStart = -1;
		int nIndexEnd = -1;

		if (m_nStartIndex<0)
		{
			m_nBackupMode = bm_ListSelected;
			if (m_nSearchType == search_time)
			{
				nIndexStart = m_pWndListTime->GetBackupIndexStart();
				nIndexEnd = m_pWndListTime->GetBackupIndexEnd();
			}
			else
			{
				nIndexStart = m_pWndListEvent->GetBackupIndexStart();
				nIndexEnd = m_pWndListEvent->GetBackupIndexEnd();
			}
		}
		else
		{

			if (m_nSearchType == search_time)
			{
				if (m_bChangeTime)
				{
					nIndexStart = m_pWndListTime->SearchIndex(m_dwBackupStartTime, TRUE);
					nIndexEnd = m_pWndListTime->SearchIndex(m_dwBackupEndTime, FALSE);
					m_nBackupMode = bm_Time;
				}
				else
				{
					nIndexStart = nIndexEnd = m_nStartIndex;
					m_nBackupMode = bm_List1;
				}
			}
			else
			{
				if (m_bChangeTime)
				{
					nIndexStart = m_pWndListEvent->SearchIndex(m_dwBackupStartTime, TRUE);
					nIndexEnd = m_pWndListEvent->SearchIndex(m_dwBackupEndTime, FALSE);
					m_nBackupMode = bm_Time;
				}
				else
				{
					nIndexStart = nIndexEnd = m_nStartIndex;
					m_nBackupMode = bm_List1;
				}
			}
			m_bChangeTime = FALSE;

		}

		if ((nIndexStart<0)||(nIndexEnd<0))
			return;

		m_pIntrBackup2->SetCallback(_CallbackBackup, this);
		m_pIntrBackup2->InitBackup(m_tzBackupPath, nIndexStart, (time_t)m_dwBackupStartTime, 
			nIndexEnd, (time_t)m_dwBackupEndTime, m_nBackupMode, m_nSearchType, m_nRecMode);

		for (i=0;i<MAX_CHANNEL;i++)
		{
			if (m_bSelCam[i])
				m_pIntrBackup2->SetSelCamera(i);
		}
		if (m_pIntrBackup2->StartBackup())
		{
			m_btnBackupStart.EnableWindow(FALSE);
			m_btnClose.EnableWindow(FALSE);
			m_btnStop.EnableWindow(TRUE);
		}
	}
	else
	{		
		CUtilString us;
		CUtilRender ur;
		CWndDisplay *pWndDisplay;
		
		pWndDisplay = CWndDisplay::CreateDisplay(CWndDisplay::DISPLAY_TYPE_DIRECTD3D9, this);

		TCHAR *ptzName;
		BYTE *pTransVideo;
		BOOL bRet;

		for (i=0;i<MAX_CHANNEL;i++)
		{
			if (IsSelCamera(i))
			{
				if (m_pImageData[i])
				{
					if (pWndDisplay)
					{
						ptzName = us.GetBitmapFileNameString(GetBackupPath(), m_tSaveTime[i], i+1);
						pTransVideo = pWndDisplay->GetPrintData(0, m_pImageData[i], m_nWidth[i], m_nHeight[i], m_nFormat[i]);
						bRet = ur.Rgb32ToBitmap(ptzName, pTransVideo, m_nWidth[i], m_nHeight[i]);
						if (!bRet)
						{
							AfxMessageBox(m_sarrMessage.GetAt(3));
							break;
						}
					}
				}
			}
		}

		delete pWndDisplay;

	}	
}

void CDlgBackup::SetFinBackup(BOOL bResult)
{
	m_btnBackupStart.EnableWindow(TRUE);
	m_btnStop.EnableWindow(FALSE);
	m_btnClose.EnableWindow(TRUE);
	

	m_pgrBackup.SetPos(0);
	SetDlgItemText(IDC_EDIT_PROGRESS_TIME, _T(""));

	if (!bResult)
	{
		AfxMessageBox(m_sarrMessage.GetAt(4));
	}
}

BOOL CDlgBackup::IsSelCamera(int nCam)
{
	if ((nCam<MAX_CHANNEL)&&(nCam>=0))
	{
		return m_bSelCam[nCam];
	}
	return  FALSE;
}

void CDlgBackup::OnBnClickedCancel()
{
	if (m_pIntrBackup2)
	{
		m_pIntrBackup2->StopBackup();
	}
	OnCancel();
}

void CDlgBackup::OnShowWindow(BOOL bShow, UINT nStatus)
{
	CDialog::OnShowWindow(bShow, nStatus);

	if (bShow)
	{
		UpdateControlData();
		UpdateData(FALSE);
		UpdateControl();
	}
}

void CDlgBackup::OnDtnDatetimechangeDatetimepickerStart(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);

	m_nUpdateID = IDC_DATETIMEPICKER_START;
	UpdateData(TRUE);
	UpdateSetting();
	UpdateData(FALSE);	// 20040408
	UpdateControl();

	m_bChangeTime = TRUE;
	*pResult = 0;
}

void CDlgBackup::OnDtnDatetimechangeDatetimepickerEnd(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);

	m_nUpdateID = IDC_DATETIMEPICKER_END;
	UpdateData(TRUE);
	UpdateSetting();
	UpdateData(FALSE);	// 20040408
	UpdateControl();
	m_bChangeTime = TRUE;
	*pResult = 0;
}

void CDlgBackup::_CallbackBackup(UINT nCmd, DWORD wParam, void* lParam, void* pApp)
{
	CDlgBackup *pDlgBak = (CDlgBackup *)pApp;
	pDlgBak->CallbackBackup(nCmd, wParam, lParam);
}

void CDlgBackup::CallbackBackup(UINT nCmd, DWORD wParam, void* lParam)
{
	int *nItem;
	CTimeList *ptIndex1, *ptIndex2;
	switch (nCmd)
	{
	case PROGRESS_SETVAL:
		{
			int nPos = (int)wParam;
			DWORD dwBackupTime;
			dwBackupTime = ((DWORD *)lParam)[0];
			SetProgressPos(nPos, dwBackupTime);
			break;
		}

	case FINISH_BAK:
		{
			SetFinBackup((BOOL)wParam);
			break;
		}
	case BACKUP_GET_TIME_INDEX:
		{
			ptIndex1 = m_pWndListTime->GetBackupIndex((int)wParam);
			ptIndex2 = (CTimeList *)lParam;
			if (ptIndex1)
				*ptIndex2 = *ptIndex1;
			else
			{
				ptIndex2->SetIndex(-1);
			}
		}
	case BACKUP_GET_TIME_NEXT:
		{
			nItem = (int *)lParam;
			*nItem = m_pWndListTime->GetBackupIndexNext((int)wParam, FALSE);
		}
		break;
	case BACKUP_GET_TIME_NEXT_CHECKED:
		{
			nItem = (int *)lParam;
			*nItem = m_pWndListTime->GetBackupIndexNext((int)wParam, TRUE);
		}
		break;

	case BACKUP_GET_EVENT_INDEX:
		{
			ptIndex1 = m_pWndListEvent->GetBackupIndex((int)wParam);
			ptIndex2 = (CTimeList *)lParam;
			if (ptIndex1)
				*ptIndex2 = *ptIndex1;
			else
			{
				ptIndex2->SetIndex(-1);
			}
		}
	case BACKUP_GET_EVENT_NEXT:
		{
			nItem = (int *)lParam;
			*nItem = m_pWndListEvent->GetBackupIndexNext((int)wParam, FALSE);
		}
		break;
	case BACKUP_GET_EVENT_NEXT_CHECKED:
		{
			nItem = (int *)lParam;
			*nItem = m_pWndListEvent->GetBackupIndexNext((int)wParam, TRUE);
		}
		break;

	}
}

void CDlgBackup::OnBnClickedBtnStop()
{
	if (m_pIntrBackup2)
	{
		m_pIntrBackup2->StopBackup();
	}
}

void CDlgBackup::OnDestroy()
{
	int i;
	for (i=0;i<MAX_CHANNEL;i++)
	{
		if (m_pImageData[i])
			delete m_pImageData[i];
		m_pImageData[i] = NULL;
	}

	CDialog::OnDestroy();

	if (m_pIntrBackup2)
	{
		delete m_pIntrBackup2;
		m_pIntrBackup2 = NULL;
	}
}

void CDlgBackup::SetCurrentImage(int nChannel, BYTE *pImage, int nWidth, int nHeight, int nFormat, time_t tSaveTime)
{
	m_nWidth[nChannel] = nWidth;
	m_nHeight[nChannel] = nHeight;
	m_nFormat[nChannel] = nFormat;

	if (m_pImageData[nChannel] != NULL)
		delete m_pImageData[nChannel];
	m_pImageData[nChannel] = new BYTE[nWidth*nHeight*4];

	int nSize = nWidth*nHeight*2;
	switch (nFormat)
	{
	case FMT_RGB:
		nSize *= 2;
		break;
	}

	memcpy(m_pImageData[nChannel], pImage, nSize);

	m_tSaveTime[nChannel] = tSaveTime;
}

void CDlgBackup::OnBnClickedButtonOpenFolder()
{
	TCHAR tzCmdLine[MAX_PATH];

	wsprintf(tzCmdLine, _T("explorer /e, \"%s\""), GetBackupPath());

	STARTUPINFO startInfo;
	PROCESS_INFORMATION processInfo;
	ZeroMemory(&startInfo, sizeof(startInfo));
	startInfo.cb = sizeof(startInfo);
	startInfo.wShowWindow = SW_SHOWNORMAL;

	CreateProcess(NULL, tzCmdLine, NULL, NULL, FALSE, 
		CREATE_BREAKAWAY_FROM_JOB|CREATE_NEW_PROCESS_GROUP, 
		NULL, NULL, &startInfo, &processInfo);

	CloseHandle(startInfo.hStdInput);
	CloseHandle(startInfo.hStdOutput);
	CloseHandle(startInfo.hStdError);

	CloseHandle(processInfo.hProcess);
	CloseHandle(processInfo.hThread);
	
}

void CDlgBackup::RefreshLang()
{
	LoadText();
}

void CDlgBackup::LoadText()
{
	//1. Dialog Name
	CString strText;
	strText.Format(_T("%s: %s"), 
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_TITLE, _T("Backup ")),
		(m_nDlgStatus == 0) ? 
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_TITLE_STATUS1, _T("Checked files in the list")) :
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_TITLE_STATUS2, _T("Current Playing File")));

	this->SetWindowText(strText);

	//2. Backup type
	GetDlgItem(IDC_STATIC_BACKUP_TYPE)->SetWindowText(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_TYPE, _T("Backup Type:")));

	GetDlgItem(IDC_RADIO_BACKUP_TYPE1)->SetWindowText(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_TYPE1, _T("AVI file")));

	GetDlgItem(IDC_RADIO_BACKUP_TYPE2)->SetWindowText(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_TYPE2, _T("BMP Image")));

	GetDlgItem(IDC_STATIC_SETTING)->SetWindowText(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_SETTING, _T("Backup Setting")));

	GetDlgItem(IDC_STATIC_CAMERA)->SetWindowText(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_CAMERA, _T("Camera :")));

	GetDlgItem(IDC_STATIC_PATH)->SetWindowText(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_PATH, _T("Path :")));

	GetDlgItem(IDC_STATIC_BACKUP_START)->SetWindowText(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_START_TIME, _T("Start Time :")));
	GetDlgItem(IDC_STATIC_BACKUP_END)->SetWindowText(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_END_TIME, _T("End Time :")));

	GetDlgItem(IDOK)->SetWindowText(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_BTN_START, _T("Start")));

	GetDlgItem(IDC_BTN_STOP)->SetWindowText(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_BTN_STOP, _T("Stop")));
	GetDlgItem(IDCANCEL)->SetWindowText(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_CLOSE, _T("Close")));
	GetDlgItem(IDC_BUTTON_OPEN_FOLDER)->SetWindowText(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_GOTO_FOLDER, _T("Go to backup folder"))
		);

	m_sarrText.RemoveAll();
	m_sarrText.Add(theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_SEL_PATH,
		_T("Select backup folder")));

	m_sarrMessage.RemoveAll();
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_MESSAGE0,
		_T("Select the channels for backup")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_MESSAGE1_0,
		_T("The End Time is earlier than the Start Time,")));
	m_sarrMessage.Add(theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_MESSAGE1_1,
		_T("adjust the Start and End Time")));

	m_sarrMessage.Add(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_MESSAGE2,
		_T("Cannot create backup bitmap file(s)"))
		);
	m_sarrMessage.Add(
		theApp.GetUIString(APPNAME_BACKUP, KEYNAME_BACKUP_MESSAGE3,
		_T("Backup is not successfully done"))
		);

}
